package fileIO;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.jdom.Element;

import storage.Employee;
import data.FilePath;

public class EmployeeInfoWriter {
	public static final int CS = 0;
	public static final int SALES = 1;
	
	public static void write(HashMap<String,ArrayList<Employee>> inputList, Map<String,Boolean> locationMap, int type){
		Element root = new Element("CSList");
		
		Object[] keyList = inputList.keySet().toArray();
		
		for(int i=0;i<keyList.length;i++){
			Element location = new Element("Location");
			
			ArrayList<Employee> empList = inputList.get(keyList[i]);
			location.setAttribute("name",(String)keyList[i]);
			location.setAttribute("origin",locationMap.get(keyList[i]).toString());
			
			for(int z =0;z<empList.size();z++){
				Element csNode = new Element("CS");
				Element name = new Element("Name");
				name.setText(empList.get(z).name);
				Element email = new Element("Email");
				email.setText(empList.get(z).email);
				csNode.addContent(name);
				csNode.addContent(email);
				location.addContent(csNode);
			}
			root.addContent(location);
		}
		if(type == CS)
			XMLWriter.writeDocument(root, FilePath.CS_LIST);
		else if(type == SALES)
			XMLWriter.writeDocument(root, FilePath.SALES_LIST);
	}
}
